<?php
namespace Admin\Controller;


class LinkController extends CommonController
{
    private $link;

    public function __construct()
    {
        parent:: __construct();
        $this->link = M('link');
    }

    public function index()
    {
        $links = $this->link->select();
        $this->assign('links', $links);
        $this->display();
    }

    public function store()
    {
//        dump($_POST);
        $this->link->create();
        $this->link->add();
        $this->success('新增成功');
    }

    public function destory()
    {
        $id = I('get.id');
        $this->link->delete($id);
        $this->success('删除成功');
    }

    public function update()
    {
        $this->link->create();
        $this->link->save();
        $this->success('修改成功');
    }

    public function delete_checked()
    {
        $id = I('post.checked_id');
        foreach ($id as $key => $value) {
            $this->link->delete($value);
        }
        $this->success('删除成功');
//        dump($_POST);
    }

    public function sort_order()
    {
        $sort_order = I('post.sort_order');
        $id = I('post.id');
        foreach ($id as $key=>$value) {
            $this->link->where("id=$value")->setField('sort_order',$sort_order[$key]);
        }
        $this->redirect('index');
//        dump($_POST);
    }


}